#!/bin/bash

info() { echo -e "\033[1;32m[INFO]\033[0m $1"; }
warn() { echo -e "\033[1;33m[WARN]\033[0m $1"; }
error() { echo -e "\033[1;31m[ERROR]\033[0m $1"; }

if ! command -v npm >/dev/null 2>&1; then
  error "npm 未安装，先从 https://nodejs.org/ 安装 Node.js 和 npm"
  exit 1
fi

if ! command -v serve >/dev/null 2>&1; then
  warn "serve 未安装，正在尝试自动安装 serve..."
  npm install -g serve
  if [ $? -ne 0 ]; then
    error "serve 安装失败，请手动执行：npm install -g serve"
    exit 1
  else
    info "serve 安装成功。"
  fi
else
  info "serve 已安装。"
fi

if [ ! -d "dev" ]; then
  error "未找到 dev 目录，确认是否存在。"
  exit 1
fi

serve dev
